<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    function Node(element){
        this.element = element;
        this.next = null;
    }

    function LList(){
        this.head = new Node('head');
        this.find = find;
        this.insert = insert;
        //this.remove = remove;
        this.display = display;
    }

    function find(item){
        var currNode = this.head;
        while (currNode.element != item){
            currNode = currNode.next;
        }
        return currNode;
    }

    //插入一个元素
    function insert(newElement, item){
        var newNode = new Node(newElement);
        var current = this.find(item);
        newNode.next = current.next;
        current.next = newNode;
    }

    function display(){
        var currNode = this.head;
        while (!(currNode.next == null)){
            document.write(currNode.next.element + '&nbsp;');
            currNode = currNode.next;
        }
    }


    //测试程序
    var cities = new LList();
    cities.insert("Conway", "head");
    cities.insert("Russellville", "Conway");
    cities.insert("Alma", "Russellville");
    cities.insert("Alma", "Russellville");
    cities.display();
</script>
</html>